<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>快速安装 - {:site('system_name', 'AphpCMS')}</title>
    <link rel="stylesheet" href="__STATIC__/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/css/other/login.css?v={:site_ver()}"/>
</head>
<body>

<form class="layui-form">
    <div class="layui-form-item">
        <img class="logo" src="__STATIC__/admin/images/logo.png" alt="aphpcms"/>
        <div class="title">{:site('system_name', 'AphpCMS')}</div>
        <div class="desc">
            一键快速还原安装(迁移)
        </div>
        <div style="line-height: 30px;color: #009688;border: 1px solid #009688;padding: 10px;">
            <ol>
                <li style="color:#c00;">配置数据库于 config/database.php</li>
                <li>复制 backup 下 bak_备份名 一键安装</li>
                <li>重装：清空数据库并删除 backup/install.lock</li>
            </ol>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-time"></i>
            </div>
            <input type="text" name="path" hover class="layui-input" placeholder="备份文件夹名 bak_***" lay-verify="required" lay-reqtext="请输入备份文件夹名" lay-affix="clear"/>
        </div>
    </div>
    <div class="layui-form-item">
        <button type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="install">一键安装</button>
    </div>
    <div class="layui-form-item" style="text-align: right;">
        <a href="__HOST__/admin.php">进入后台</a> | <a href="__HOST__">进入前台</a>
    </div>
</form>

<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'aphp', 'layer'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
        form.on('submit(install)', function (data) {
            const loadIndex = layer.msg('还原安装中，请耐心等待……', {icon: 16, time: 60000});
            $.post("{:url('index')}", {path: data.field.path}, function (ret) {
                if (ret.status === 1) {
                    layer.alert(ret.msg, {
                        icon: 1,
                        title: '提示',
                        btn: ['进入后台', '进入前台'],
                        btnAlign: 'c', // 按钮居中显示
                        btn1: function(){
                            window.location.href = '__HOST__/admin.php';
                        },
                        btn2: function(){
                            window.location.href = '__HOST__';
                        }
                    });
                } else {
                    layer.alert(ret.msg, {icon: 2, title: '提示'});
                }
                layer.close(loadIndex);
            }, 'json');
            return false;
        });
    })
    layui.$(document).ready(function () {
        if (window !== top) {
            top.location.href = location.href;
        }
    });
</script>
</body>
</html>